# -*- coding: utf-8 -*-
from django.db import models

# Create your models here.
from django.contrib import admin
from django.contrib.auth.models import User
import django.utils.timezone as timezone

# 单选题：题库 by hcq
# 标签：s
class SingleSelectProblem(models.Model):
    # QuestionID = 1 2 3 4 ...
    QuestionID = models.IntegerField(primary_key = True,verbose_name = u'单选题ID')
    CourseID = models.CharField(max_length = 10,verbose_name = u'课程ID')
    QuestionTitle = models.CharField(max_length = 2000,verbose_name = u'题目')
    OptionA = models.CharField(max_length = 1000,verbose_name = u'选项A')
    OptionB = models.CharField(max_length = 1000,verbose_name = u'选项B')
    OptionC = models.CharField(max_length = 1000,verbose_name = u'选项C')
    OptionD = models.CharField(max_length = 1000,verbose_name = u'选项D')
    SingleAnswer = models.CharField(max_length = 10, verbose_name = u'答案')
    Analysis = models.CharField(max_length = 4000, null = True, verbose_name = u'试题解析')
    Weight = models.CharField(max_length = 10, verbose_name = u'分值')
    Note = models.CharField(default = 'None', max_length = 200, verbose_name = u'备注')

    def __unicode__(self):
        return  str(self.QuestionID) + '_' + self.SingleAnswer + '_' + self.QuestionTitle

# 判断题：题库 by hcq
# 标签：j
class JudgementProblem(models.Model):
    # QuestionID = 1 2 3 4 ...
    QuestionID = models.IntegerField(primary_key = True,verbose_name = u'单选题ID')
    CourseID = models.CharField(max_length = 10,verbose_name = u'课程ID')
    QuestionTitle = models.CharField(max_length = 2000,verbose_name = u'题目')
    # JudgementAnswer: ture --> A   false --> B
    JudgementAnswer = models.CharField(max_length = 10, verbose_name = u'答案')
    Analysis = models.CharField(max_length = 4000, null = True, verbose_name = u'试题解析')
    Weight = models.CharField(max_length = 10, verbose_name = u'分值')
    Note = models.CharField(default = 'None', max_length = 200, verbose_name = u'备注')

    def __unicode__(self):
        return  str(self.QuestionID) + '_' + self.JudgementAnswer + '_' + self.QuestionTitle

# 课程表
class Course(models.Model):
    # CourseID = 001 002 003 ...
    CourseID = models.CharField(primary_key = True, max_length = 10, verbose_name = u'课程ID')
    CourseName = models.CharField(max_length = 100, verbose_name = u'课程名称')
    Note = models.CharField(default = 'None', max_length = 200, verbose_name = u'备注')

    def __unicode__(self):
        return self.CourseID + '_' + self.CourseName

# 试卷信息表 by hcq
# 适用于选择题和判断题
# 填空题的话，需要其他table
class ExamPaperInfo(models.Model):
    # ExamID 统一使用当前时间为值，例如：2017_4_2_21_46
    ExamID = models.CharField(primary_key = True, max_length = 40,verbose_name = u'试卷编号')
    ExamName = models.CharField(max_length = 100, verbose_name = u'试卷名')
    # ExamQuestions:标签+QuestionID
    # 选择题：s1_s2_s4_s10
    # 判断题：j1_j2_j4_j8_j10
    # 试卷题目：s1_s2_s4_s10_j1_j2_j4_j8_j10_s20_j99
    # 带有s标签的就去单选题的题库匹配，带有j标签的就去判断题的题库匹配，后续可扩展
    ExamQuestions = models.CharField(max_length = 2000, verbose_name = u'试卷题目')
    CourseID = models.CharField(max_length = 100, verbose_name = u'课程ID')
    ExamTime = models.CharField(max_length = 10, verbose_name = u'考试时长')
    ProblemNum = models.CharField(max_length = 10, null = True, verbose_name = u'题量')
    TotalScore = models.CharField(max_length = 10, verbose_name = u'总分')
    TeacherID = models.CharField(max_length = 20, verbose_name = u'出题者ID')
    Note = models.CharField(default = 'None', max_length = 200, verbose_name = u'备注')

    def __unicode__(self):
        return self.ExamID + "," + self.ExamName

# 试卷详细信息
# 存储每一道题及其对应的答案
# class ExamPaperDetailInfo(models.Model):


# 考生答案表
# 适用于选择题和判断题
# 填空题的话，需要其他table
class ExamStuAnswered(models.Model):
    StuID = models.CharField(max_length = 20, verbose_name = u'学生ID')
    ExamID = models.CharField(max_length = 40, verbose_name = u'试卷编号')
    # ExamAnswer = A_B_A_B_A_B_A_B_A_D_A_B_C
    ExamAnswer = models.CharField(max_length = 2000, verbose_name = u'参考答案')
    # AnsweredStr = A_B_A_B_A_B_A_B_A_D_A_B_C
    AnsweredStr = models.CharField(max_length = 2000, verbose_name = u'考生答案')
    # 收藏: LinkedStr = s1_s2_s4_s10_j1_j2_j4_j8_j10_s20_j99
    LinkedStr = models.CharField(max_length = 1000, null = True, verbose_name = u'收藏的题目')
    Note = models.CharField(default = 'None', max_length = 200, verbose_name = u'备注')

    # 多个主键
    class Meta:
        unique_together = ('StuID', 'ExamID')

    def __unicode__(self):
        return self.StuID + '__' + self.ExamID + '__' + self.AnsweredStr

# 成绩表
class ScoreInfo(models.Model):
    StuID = models.CharField(max_length = 20, verbose_name = u'学生ID')
    ExamID = models.CharField(max_length = 40, verbose_name = u'试卷编号')
    Score = models.CharField(max_length = 10, verbose_name = u'考生成绩')
    ExamState = models.NullBooleanField(default = False, verbose_name = u'考试状态')
    Note = models.CharField(default = 'None', max_length = 200, verbose_name = u'备注')

    # 多个主键
    class Meta:
        unique_together = ('StuID', 'ExamID')

    def __unicode__(self):
        return self.StuID + '__' + self.ExamID + '__' + self.Score

